package com.ygou.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ygou.pojo.Slide;
import com.ygou.pojo.Websideset;
import com.ygou.service.WebsidesetService;
import com.ygou.service.impl.SlideServiceImpl;
import com.ygou.utils.jedis.RedisUtil;

@Controller
public class InitController {
	@Autowired
	private SlideServiceImpl sService;
	@Autowired
	private WebsidesetService websidesetService;
	@Autowired
	private RedisUtil redisUtil;
	
	@RequestMapping(value="/init")
	public String init(HttpSession session){
		List<Slide> slides = (List<Slide>) redisUtil.lGet("slides", 0, -1);
		if(slides==null || slides.size()==0){
			slides=sService.showAll();
			redisUtil.lSet("slides", slides);
			//redisUtil.set("slides",slides);
		}
		//List<Slide> slides=sService.showAll();
		Websideset websideset = websidesetService.selectByPrimaryKey(1);
		session.setAttribute("slides",slides);
		session.setAttribute("web",websideset);
		return "redirect:/index.jsp";
	}
}
